package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.google.gson.JsonObject;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DeviceController
 * @Author fy
 * @Date 2025-05-19  16:57
 */
@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController extends BaseController {
    @Autowired
    private DeviceService deviceService;
    @PostMapping("/syncProductList")
    @ApiOperation("从物联网平台同步产品列表")
    public ResponseResult syncProductList(){
        deviceService.syncProductList();
        return success();

    }

    /**
     * 查询所有产品列表
     * @return
     */
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProductList(){
        List<ProductVo> list = deviceService.allProductList();
        return success(list);

    }

    /**
     * 注册设备
     * @param deviceDto
     * @return
     */
    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return success();
    }

    /**
     * 分页查询设备列表
     * @param devicePageQueryDto
     * @return
     */
    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备列表")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto){
       PageResponse<DeviceVo> list = deviceService.pageQueryDevice(devicePageQueryDto);
       return success(list);
    }

    /**
     * 查询设备详细数据
     * @param request
     * @return
     */
    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详细数据")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest request){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(request);
        return success(deviceVo);
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param queryThingModelPublishedRequest
     * @return
     */
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult<ThingModelVo> queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest queryThingModelPublishedRequest){
        ThingModelVo thingModelVo = deviceService.queryThingModelPublished(queryThingModelPublishedRequest);
        return success(thingModelVo);
    }

    /**
     * 查询指定设备的物模型运行状态
     * @param request
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult<DevicePropertystatus> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        DevicePropertystatus devicePropertystatus= deviceService.queryDevicePropertyStatus(request);
        return success(devicePropertystatus);
    }
    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.updateDevice(deviceDto);
        return  success();
    }
    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceRequest request){
        deviceService.deleteDevice(request);
        return success();
    }
}
